package  com.slicktechnologies.client.views.account.expensemanagment;


import java.util.Vector;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.InlineLabel;
import com.simplesoftwares.client.library.appskeleton.AppMemory;
import com.simplesoftwares.client.library.appstructure.SearchPopUpScreen;
import com.simplesoftwares.client.library.appstructure.SuperTable;
import com.simplesoftwares.client.library.appstructure.formscreen.FormScreen;
import com.simplesoftwares.client.library.appstructure.formscreen.FormScreenPresenter;
import com.simplesoftwares.client.library.appstructure.search.Filter;
import com.simplesoftwares.client.library.appstructure.search.MyQuerry;
import com.simplesoftwares.rebind.annatonations.EntityNameAnnotation;
import com.slicktechnologies.client.utility.GeneratedVariableRefrence;
import com.slicktechnologies.shared.common.businessprocesslayer.Expense;

/**
 *  Expense Managment Presenter
 */
public class ExpensemanagmentPresenter extends FormScreenPresenter<Expense>  {

	//Token to set the concrete form
	/** The form. */
	ExpensemanagmentForm form;
	//CsvServiceAsync csvservice=GWT.create(CsvService.class);
	
	/**
	 * Instantiates a new expensemanagment presenter.
	 *
	 * @param view the view
	 * @param model the model
	 */
	public ExpensemanagmentPresenter (FormScreen<Expense> view,
			Expense model) {
		super(view, model);
		form=(ExpensemanagmentForm) view;
		form.setPresenter(this);
		form.getSearchpopupscreen().getPopup().setWidth("1500px");
		
	}

	
	/* (non-Javadoc)
	 * @see com.simplesoftwares.client.library.appstructure.EntityPresenter#reactOnPrint()
	 */
	@Override
	public void reactOnPrint() {
		
	}

	/* (non-Javadoc)
	 * @see com.simplesoftwares.client.library.appstructure.EntityPresenter#reactOnEmail()
	 */
	@Override
	public void reactOnEmail() {
		
		
	}
	
	/*@Override
	public void reactOnDownload() 
	{
		ArrayList<Expense> custarray=new ArrayList<Expense>();
		List<Expense> list=(List<Expense>) form.getSearchpopupscreen().getSupertable().getDataprovider().getList();
		
		custarray.addAll(list);
		
		csvservice.setexpenselist(custarray, new AsyncCallback<Void>() {

			@Override
			public void onFailure(Throwable caught) {
				System.out.println("RPC call Failed"+caught);
				
			}

			@Override
			public void onSuccess(Void result) {
				

				String gwt=com.google.gwt.core.client.GWT.getModuleBaseURL();
				final String url=gwt + "csvservlet"+"?type="+4;
				Window.open(url, "test", "enabled");
				
			}
		});

	}*/
	
	
	
	

	/**
	 * Method template to set new model.
	 */
	@Override
	protected void makeNewModel() {
		
		model=new Expense();
	}
	
	/*
	 * Method template to set Myquerry object
	 */
	/**
	 * Gets the expense query.
	 *
	 * @return the expense query
	 */
	public MyQuerry getExpenseQuery()
	{
		MyQuerry quer=new MyQuerry(new Vector<Filter>(), new Expense());
		return quer;
	}
	
	/* (non-Javadoc)
	 * @see com.simplesoftwares.client.library.appstructure.EntityPresenter#setModel(com.simplesoftwares.client.library.appstructure.SuperModel)
	 */
	public void setModel(Expense entity)
	{
		model=entity;
	}
	
	/**
	 * Initalize.
	 */
	public static void initalize()
	{
			 ExpensemanagmentPresenterTable gentableScreen=new ExpensemanagmentPresenterTableProxy();
			
			ExpensemanagmentForm  form=new  ExpensemanagmentForm();
			gentableScreen.setView(form);
			gentableScreen.applySelectionModle();
			
			ExpensemanagmentPresenterTable gentableSearch=new ExpensemanagmentPresenterTableProxy();
			gentableSearch.setView(form);
			gentableSearch.applySelectionModle();
			
			ExpensemanagmentPresenterSearch.staticSuperTable=gentableSearch;
			ExpensemanagmentPresenterSearch searchpopup=new ExpensemanagmentPresenterSearchProxy();
			form.setSearchpopupscreen(searchpopup);
			
			 ExpensemanagmentPresenter  presenter=new  ExpensemanagmentPresenter  (form,new Expense());
			AppMemory.getAppMemory().stickPnel(form);
			
			
		 
	}
	
	@Override
	public void reactToProcessBarEvents(ClickEvent e) 
	{
		
		InlineLabel label=(InlineLabel) e.getSource();
		String text=label.getText().trim();

		
		if(text.equals("New"))
			reactToNew();
	}
	
	private void reactToNew()
	{
		form.setToNewState();
		this.initalize();
		form.toggleAppHeaderBarMenu();
	}
	
	
		/**
		 * The Class ExpensemanagmentPresenterTable.
		 */
		@EntityNameAnnotation(EntityName = "com.slicktechnologies.shared.common.businessprocesslayer.Expense")
		 public static class  ExpensemanagmentPresenterTable extends SuperTable<Expense> implements GeneratedVariableRefrence{

			/* (non-Javadoc)
			 * @see com.slicktechnologies.client.utility.GeneratedVariableRefrence#getVarRef(java.lang.String)
			 */
			@Override
			public Object getVarRef(String varName) {
		
				return null;
			}

			/* (non-Javadoc)
			 * @see com.simplesoftwares.client.library.appstructure.SuperTable#createTable()
			 */
			@Override
			public void createTable() {
		
				
			}

			/* (non-Javadoc)
			 * @see com.simplesoftwares.client.library.appstructure.SuperTable#initializekeyprovider()
			 */
			@Override
			protected void initializekeyprovider() 
			{
	
				
			}

			/* (non-Javadoc)
			 * @see com.simplesoftwares.client.library.appstructure.SuperTable#addFieldUpdater()
			 */
			@Override
			public void addFieldUpdater() 
			{
		
				
			}

			/* (non-Javadoc)
			 * @see com.simplesoftwares.client.library.appstructure.SuperTable#setEnable(boolean)
			 */
			@Override
			public void setEnable(boolean state)
			{
			
				
			}

			/* (non-Javadoc)
			 * @see com.simplesoftwares.client.library.appstructure.ViewContainer#applyStyle()
			 */
			@Override
			public void applyStyle() 
			{

				
			}} ;
			
			/**
			 * The Class ExpensemanagmentPresenterSearch.
			 */
			@EntityNameAnnotation(EntityName = "com.slicktechnologies.shared.common.businessprocesslayer.Expense")
			 public static class  ExpensemanagmentPresenterSearch extends SearchPopUpScreen<  Expense>{

				/* (non-Javadoc)
				 * @see com.simplesoftwares.client.library.appstructure.SearchPopUpScreen#getQuerry()
				 */
				@Override
				public MyQuerry getQuerry() {
			
					return null;
				}};
}
